#! /bin/sh
#
# chkconfig: - 94 66
# description:  Logs alerted
# processname: logsalt
# config: 
# pidfile: /var/run/logsalt.pid


# Check that networking is up.
#. /etc/sysconfig/network


if [ "$NETWORKING" = "no" ]
then
        exit 0
fi

RETVAL=0
prog="logsalt"
pidfile="/var/run/logsalt.pid"
starter=

msg(){
        echo "[$(tput setaf $2)$1$(tput sgr 0)]"
}

status(){
        if [ $(tail -1 $pidfile 2> /dev/null) ] ; then 
                return 0 
        else 
                return 1
        fi
}

activate(){
        if status ; then
                msg "ok" 2
                exit 0
        else
                echo "Some problem related to $prog program occured..."
                msg "fail" 1
                exit 1
        fi
}

start () {
        if [ -f $pidfile ] ; then
                echo "Service already running..."
                msg "fail" 1
                exit 1
        fi
        $starter > /dev/null 2> /dev/null & echo $! > $pidfile
        activate
}
stop () {
        if [ -f $pidfile ] ; then
                kill -KILL $(tail -1 $pidfile) 2> /dev/null
                rm -rf $pidfile
                msg "ok" 2
        else
                echo "No pid file $pidfile found. cant stop !!!"
                msg "fail" 1
        fi
}

restart () {
        stop
        start
}



# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status
        ;;
  restart)
        restart
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart}"
        RETVAL=2
        ;;
esac

exit $RETVAL

